import {
  apiBaseUrl,
  warmBgColor,
  coolBgColor,
  successInfoBgColor,
  failInfoBgColor,
  textNormalColor,
  fieldNameColor,
  logo2ImageSrc,
  originImageSrc,
} from './config.js';
import {
  anitShakeExecuteCallback,
} from './utils/common';
// import {
//   wxUserManager,
// } from './utils/wxUserManager';
// import {storagerWxopenidAndUserInfo} from './utils/storagerWxopenidAndUserInfo';
var coolsite360 = require('./coolsite/index.js');
wx.cloud.init({
  traceUser: true
});
const db = wx.cloud.database();
App({
  // storagerWxopenidAndUserInfo,
  coolsite360: coolsite360,

  //第一种状态的底部  
  editTabBar: function () {
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
    var _pagePath = _curPage.__route__;
    if (_pagePath.indexOf('/') != 0) {
      _pagePath = '/' + _pagePath;
    }
    var tabBar = this.globalData.tabBar;
    for (var i = 0; i < tabBar.list.length; i++) {
      tabBar.list[i].active = false;
      if (tabBar.list[i].pagePath == _pagePath) {
        tabBar.list[i].active = true; //根据页面地址设置当前页面状态    
      }
    }
    _curPage.setData({
      tabBar: tabBar
    });
  },

  exit: function () {
    wx.clearStorageSync(); //同步清空本地缓存
    wx.redirectTo({
      url: '/page/index/index',
    })
  },

  //第二种状态的底部  
  editTabBarTeacher1: function () {
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
    var _pagePath = _curPage.__route__;
    if (_pagePath.indexOf('/') != 0) {
      _pagePath = '/' + _pagePath;
    }
    var tabBar = this.globalData.tabBarTeacher1;
    for (var i = 0; i < tabBar.list.length; i++) {
      tabBar.list[i].active = false;
      if (tabBar.list[i].pagePath == _pagePath) {
        tabBar.list[i].active = true; //根据页面地址设置当前页面状态    
      }
    }
    _curPage.setData({
      tabBar: tabBar
    });
  },
  editTabBarTeacher2: function () {
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
    var _pagePath = _curPage.__route__;
    if (_pagePath.indexOf('/') != 0) {
      _pagePath = '/' + _pagePath;
    }
    var tabBar = this.globalData.tabBarTeacher2;
    for (var i = 0; i < tabBar.list.length; i++) {
      tabBar.list[i].active = false;
      if (tabBar.list[i].pagePath == _pagePath) {
        tabBar.list[i].active = true; //根据页面地址设置当前页面状态    
      }
    }
    _curPage.setData({
      tabBar: tabBar
    });
  },
  globalData: {
    wxopenid: '',
    globalAntiShakeTimer: null, // 这是全局防抖定时器，为null时相应的函数才会被执行
    anitShakeExecuteCallback, // 只是供全局调用的防抖定时器
    apiBaseUrl,
    warmBgColor,
    coolBgColor,
    successInfoBgColor,
    failInfoBgColor,
    textNormalColor,
    fieldNameColor,
    logo2ImageSrc,
    originImageSrc,
    userInfo: null,
    pop: 2,
    num: 0,
    tabBar: {
      "color": "#999999",
      "selectedColor": warmBgColor,
      "borderStyle": "white",
      "backgroundColor": "#F2F2F2",
      "list": [
        {
          "pagePath": "/page/student/page/five/five",
          "text": "我",
          "iconPath": "/resources/my-avatar.png",
          "selectedIconPath": "/resources/my-avatar-selected.png",
          "selectedColor": warmBgColor,
          "clas": "menu-item",
          active: true
        },
        {
          "pagePath": "/page/student/page/two/two",
          "text": "请假",
          "iconPath": "/resources/ask-for-leavy.png",
          "selectedIconPath": "/resources/ask-for-leavy-selected.png",
          "clas": "menu-item",
          "selectedColor": warmBgColor,
          active: false
        },
        {
          "pagePath": "/page/student/page/three/three",
          "text": "休假记录",
          "iconPath": "/resources/leavy-record.png",
          "selectedIconPath": "/resources/leavy-record-selected.png",
          "selectedColor": warmBgColor,
          "clas": "menu-item",
          active: false
        }
      ],
      "position": "bottom"
    },
    tabBarTeacher1: {
      "color": textNormalColor,
      "selectedColor": warmBgColor,
      "borderStyle": "#ccc",
      "backgroundColor": "#F2F2F2",
      "list": [
        {
          "pagePath": "/page/teacher/page/five/five",
          "text": "我",
          "iconPath": "/resources/my-avatar.png",
          "selectedIconPath": "/resources/my-avatar-selected.png",
          "selectedColor": warmBgColor,
          "clas": "menu-item2",
          active: true
        },
        {
          "pagePath": "/page/teacher/page/one/one",
          "text": "批假",
          "iconPath": "/resources/ask-for-leavy.png",
          "selectedIconPath": "/resources/ask-for-leavy-selected.png",
          "selectedColor": warmBgColor,
          "clas": "menu-item2",
          active: false,
        },
        {
          "pagePath": "/page/teacher/page/three/three",
          "text": "休假记录",
          "iconPath": "/resources/leavy-record.png",
          "selectedIconPath": "/resources/leavy-record-selected.png",
          "clas": "menu-item2",
          "selectedColor": warmBgColor,
          active: false,
        }
      ],
      "position": "bottom"
    },
    tabBarTeacher2: {
      "color": textNormalColor,
      "selectedColor": warmBgColor,
      "borderStyle": "#ccc",
      "backgroundColor": "#F2F2F2",
      "list": [
        {
          "pagePath": "/page/teacher/page/five/five",
          "text": "我",
          "iconPath": "/resources/my-avatar.png",
          "selectedIconPath": "/resources/my-avatar-selected.png",
          "selectedColor": warmBgColor,
          "clas": "menu-item2",
          active: true
        },
        {
          "pagePath": "/page/teacher/page/one/one",
          "text": "批假",
          "iconPath": "/resources/ask-for-leavy.png",
          "selectedIconPath": "/resources/ask-for-leavy-selected.png",
          "selectedColor": warmBgColor,
          "clas": "menu-item2",
          active: false,
        },
        {
          "pagePath": "/page/teacher/page/three/three",
          "text": "休假记录",
          "iconPath": "/resources/leavy-record.png",
          "selectedIconPath": "/resources/leavy-record-selected.png",
          "clas": "menu-item2",
          "selectedColor": warmBgColor,
          active: false,
        }
      ],
      "position": "bottom"
    }
  }
})